<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/js/axios.min.js"></script>
    <script src="/html/js/ajax.js"></script>
    <script>
        var id
        window.onload=function (){
            //得到前一个页面传递过来的参数
            id=getQuery("id");
            init(id);
        }
        async function init(id){
            let deptList=await ajaxGet("/dept/findAll");
            console.log(deptList);
            let emObj=await ajaxGet("/employee/findById",{id:id});
            let str="";
            for (let i=0;i<deptList.length;i++){
                let obj=deptList[i];
                str+=`<option value="${obj.id}">${obj.name}</option>`
            }
            console.log(str)
            getObject("deptSelect").innerHTML=str;

            getObject("nameSpan").innerHTML=emObj.name;
            getObject("birthdaySpan").innerHTML=emObj.birthday;
            getObject("money").value=emObj.money;
            getObject("deptSelect").value=emObj.deptBean.id;
        }

        async function update(){
            let obj={id:id,depetId:getObject("deptSelect").value,money:getObject("money").value};
            let info=await ajaxGet("/employee/update",obj)
            if (info=="ok"){
                location.href="/html/index.html";
            }else {
                alert("修改失败")
            }
        }
    </script>
</head>
<body>
    姓名:<span id="nameSpan"></span><br>
    生日:<span id="birthdaySpan"></span><br>
    工资:<input type="text" id="money"><br>
    部门:<select id="deptSelect"></select><br>
    <input type="submit" value="修改" onclick="update()">
</body>
</html>